﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Web;
using System.ServiceModel.Activation;
using System.Data;
using System.ComponentModel;

namespace CRMSystemV2.Service
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“CRMSystemAPI”。
    //以下所有返回内容均按一下格式返回：
    //{"status":300,"message":"用户名不存在"}

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class CRMSystemAPI : ICRMSystemAPI
    {
        private readonly BLL.User userBll = new BLL.User();
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public string Login(string username, string password)
        {
            return userBll.Login(username, password);
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="username"></param>
        /// <param name="oldPassword"></param>
        /// <param name="newPassword"></param>
        /// <returns></returns>
        public string ChangePassword(string username, string oldPassword, string newPassword)
        {
            return userBll.ChangePassword(username, oldPassword, newPassword);
        }
        /// <summary>
        /// 分页获取用户列表
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="rowTotal"></param>
        /// <param name="pageTotal"></param>
        /// <param name="keyWords"></param>
        /// <param name="orderField"></param>
        /// <param name="orderDirection"></param>
        /// <returns></returns>
        public DataTable UserPageView(out int rowTotal, out int pageTotal, int pageSize, int pageIndex, Dictionary<string, string> keyWords, string orderField, string orderDirection)
        {
            return userBll.GetPageView(pageSize, pageIndex, out rowTotal, out pageTotal, keyWords, orderField, orderDirection);
        }
        /// <summary>
        /// 用户导出
        /// </summary>
        /// <param name="maxTotal"></param>
        /// <param name="keyWords"></param>
        /// <param name="orderField"></param>
        /// <param name="orderDirection"></param>
        /// <returns></returns>        
        public DataTable UserExportTable(int maxTotal, Dictionary<string, string> keyWords, string orderField, string orderDirection)
        {
            return userBll.GetExportTable(maxTotal, keyWords, orderField, orderDirection);
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="username"></param>
        /// <param name="jobno"></param>
        /// <param name="email"></param>
        /// <param name="phone"></param>
        /// <param name="isenable"></param>
        /// <returns></returns>
        public string UserInsert(string username, string jobno, string email, string phone, int isenable)
        {
            Model.User model = new Model.User()
            {
                UserName = username,
                JobNO = jobno,
                Email = email,
                Phone = phone,
                IsEnable = isenable == 1 ? true : false
            };
            return userBll.Insert(model);
        }
        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="id"></param>
        /// <param name="username"></param>
        /// <param name="jobno"></param>
        /// <param name="email"></param>
        /// <param name="phone"></param>
        /// <param name="isenable"></param>
        /// <returns></returns>
        public string UserUpdate(int id, string username, string jobno, string email, string phone, int isenable)
        {
            Model.User model = new Model.User()
            {
                ID = id,
                UserName = username,
                JobNO = jobno,
                Email = email,
                Phone = phone,
                IsEnable = isenable == 1 ? true : false
            };
            return userBll.Update(model);
        }
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>        
        public string ResetPassword(string id)
        {
            return userBll.ResetPassword(id);
        }
        /// <summary>
        /// 删除用户，支持批量删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>        
        public string UserDelete(string ids)
        {
            return userBll.Delete(ids);
        }
        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>        
        public Model.User GetUser(string id)
        {
            return userBll.GetUser(id);
        }
    }
}
